const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getIntegralRule(); //获取魔法币规则
  },
  /**
   * @xk 获取魔法币规则
   */
  getIntegralRule: function () {
    var that = this,
      user_id = wx.getStorageSync('user_id');
    https.post('getIntegralRule', {
      user_id: user_id
    }, false, '加载中').then(res => {
      that.setData({
        integral_info: res.info,
        rule_list: res.rule_list
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow();
  },

  goHome() {
    wx.switchTab({
      url: '/pages/home/home',
    })
  },
  goBook() {
    wx.navigateTo({
      url: '/pages/register_appointment/register_appointment',
    })
  },
  goOrder() {
    wx.navigateTo({
      url: '/pages/my_order/my_order',
    })
  },
  goBuy() {
    wx.switchTab({
      url: '/pages/shopping_mall/shopping_mall',
    })
  },
  goPush() {
    wx.navigateTo({
      url: '/pages/extension/extension',
    })
  },
  goGrant() {
    wx.navigateTo({
      url: '/pages/grant/grant',
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var timestamp = Date.parse(new Date()),
      app_name = wx.getStorageSync('app_name'),
      app_logo = wx.getStorageSync('app_logo'),
      user_id = wx.getStorageSync('user_id'),
      url = '/pages/home/home',
      timestr = timestamp / 1000;
    url += '?timestr=' + timestr;
    if (user_id > 0) {
      url += '&l_id=' + user_id;
    }
    return {
      title: app_name,
      path: url,
      imageUrl: app_logo
    }
  }
})